package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * 用户人群业务相关
 */
@Tag(name = "用户人群管理")
@RestController
@Slf4j
public class UserGroupController {
    @Autowired
    private UserGroupService userGroupService;


    @Operation(summary = "人群数据分页列表")
    @PostMapping("/admin/basic/userGroup/list")
    public Result<PageResult<UserGroupVO>> pageList(@RequestBody UserGroupQuery userGroupQuery)throws BusinessException{
        PageResult<UserGroupVO> voPage = userGroupService.pageList(userGroupQuery);
        return new Result<>(voPage);
    }
    
    @Operation(summary = "更新人群启用状态")
    @PostMapping("/admin/basic/userGroup/updateStatus")
    public Result<Void> updateStatus(@RequestBody UserGroupParam param) throws BusinessException {
        log.info("更新人群启用状态，入参：{}", param);
        userGroupService.updateStatus(param);
        return Result.success();
    }

    @Operation(summary = "删除人群数据")
    @PostMapping("/admin/basic/userGroup/delete/{id}")
    public Result<Void> delete(@PathVariable("id") Integer id) throws BusinessException {
        log.info("删除人群数据，入参：{}",id);
        return Result.success();
    }



    @Operation(summary = "查询人群详情")
    @GetMapping("/admin/basic/userGroup/detail/{id}")
    public Result<UserGroupVO> detail(@PathVariable("id") Integer id)throws BusinessException{
        log.info("查询人群详情，入参：{}",id);
       UserGroupVO vo = userGroupService.detail(id);
       log.info("查询人群详情成功，出参：{}",vo);
        return new Result<>( vo);
    }
    @Operation(summary = "新增人群")
    @PostMapping("/admin/basic/userGroup/save")
    public Result<Void> addGroup(@RequestBody UserGroupParam param) throws BusinessException, ParseException {
        log.info("新增人群，入参：{}", param);
        userGroupService.updateGroup(param);
        return Result.success();
    }
    @Operation(summary = "修改人群")
    @PostMapping("/admin/basic/userGroup/update")
    public Result<Void> updateGroup(@RequestBody UserGroupParam param) throws BusinessException, ParseException {
        log.info("更新人群，入参：{}", param);
        userGroupService.updateGroup(param);
        return Result.success();
    }



}